#pragma once
#include <memory>
#include <string>
#include <vector>
#include <glm/glm.hpp>

namespace kanon
{
    enum class ShaderSourceType
    {
        SHADER_TYPE_VERTEX,
        SHADER_TYPE_FRAGMENT,
    };

    std::string GetShaderTypeString(ShaderSourceType type);

    class Shader
    {
    private:
        uint32_t shader_id = -1;
    public:
        static std::shared_ptr<Shader> FromSources(const std::string& vertex_shader, const std::string& fragment_shader);
        static std::shared_ptr<Shader> FromShaderFiles(const std::string& vertex_path, const std::string& fragment_path);

    public:
        Shader();
        ~Shader();

        void Bind();
        void Unbind();

        void set_matrix(const std::string& name, const glm::mat4& m) const;
        void set_texture_slot(const std::string& name, int slot) const;
        void set_texture_array(const std::string& name, int* slots, int size) const;

    private:
        int32_t LoadShaderSource(const std::string& shader_source, ShaderSourceType shader_type);
        int32_t LinkProgram(uint32_t vertex_shader, uint32_t fragment_shader);
        bool LoadFileContent(const std::string& filepath, std::vector<char>& source);
    };
}
